<template>
  <div>
    <router-view />
    <div id="navbar" class="navbar">
      <div
        class="publish_tasks"
        @click="handleReleaseTask"
        v-if="identity != 'user'"
      >
        <img height="100" :src="publish_tasks" alt="发布任务" />发布任务
      </div>
      <div
        class="publish_tasks"
        @click="handleRecommendCompany"
        v-if="identity === 'user'"
      >
        <img height="100" :src="recommend_icon" alt="合作企业" />合作企业
      </div>
      <div
        v-for="nav in navbar"
        :key="nav.path"
        class="navbar-item"
        :class="{ active: nav.path === currentPath }"
        @click="togglePath(nav.path)"
      >
        <i
          :style="{
            backgroundImage:
              nav.path === currentPath
                ? `url(${nav.activeIcon})`
                : `url(${nav.icon})`,
          }"
          class="ling-icon navbar-icon animated"
          :class="{ bounceIn: nav.path === currentPath }"
        ></i>
        <div class="navbar-item-title">{{ nav.name }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import publish_tasks from '@/assets/images/publish_tasks.png'
import recommend_icon from '@/assets/images/recommend_icon.png'
import { getIdentity } from '@/utils/userAuth'
import { navbar } from '../utils/config'
import { createNamespacedHelpers } from 'vuex'
const { mapState, mapActions } = createNamespacedHelpers('myData')
export default {
  name: 'NavBar',
  data: function () {
    let currentPath = this.$route.path
    if (currentPath === '/') currentPath = '/home'
    return {
      navbar,
      currentPath,
      publish_tasks,
      recommend_icon,
      identity: getIdentity(),
    }
  },
  watch: {
    $route(to) {
      let { path } = to
      // if (path === '/') path = '/home'
      this.currentPath = path
    },
  },
  created() {
    // const { auditStatus } = this.companyUserDetail.zbCompanyResponse
    // console.log(auditStatus, 'auditStatus')
  },
  computed: {
    ...mapState(['companyUserDetail']),
  },
  methods: {
    togglePath: function (path) {
      if (path !== this.currentPath) {
        this.currentPath = path
        this.$router.push({ path })
      }
    },
    handleReleaseTask() {
      if (getIdentity() == 'company') {
        const { auditStatus } = this.companyUserDetail.zbCompanyResponse
        console.log(auditStatus, 'auditStatus')
        if (auditStatus == 'AUDITED') {
          this.$router.push('releaseTask')
        } else {
          this.$toast('资质审核中，请耐心等待')
        }
      } else {
        this.$router.push('/login')
      }
    },
    handleRecommendCompany() {
      if (getIdentity() == 'user') {
        this.$router.push(`/recommendCompany`)
      } else {
        this.$router.push('/login')
      }
    },
  },
}
</script>

<style scoped lang="less">
.navbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  text-align: center;
  align-items: center;
  width: 100%;
  line-height: 1;
  box-shadow: 0 0 2px #ddd;
  color: #333;
  background: #fff;
  z-index: 10;
  .publish_tasks {
    width: 64px;
    border-radius: 2px #fff solid;
    position: absolute;
    font-size: 10px;
    bottom: 5px;
    margin-left: -32px;
    left: 50%;
    color: #333333;
    z-index: 11;
    text-align: center;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    img {
      display: block;
      position: relative;
      top: 10px;
    }
  }
}
.navbar-item {
  flex-grow: 1;
  padding: 5px 0;
  position: relative;
  transition: color 0.3s linear 0.3s;
  /* &:not(:last-child):after {
    content: '';
    position: absolute;
    right: 0;
    top: 20%;
    width: 0.5px;
    height: 60%;
    background: #f1f1f1;
  }*/
  &.active {
    color: #333;
  }
}
.navbar-item-title {
  font-size: 10px;
  padding-top: 6px;
}
.navbar-icon {
  padding-top: 14px;
}
</style>